<template>
  <div class="mt-3 ">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :lg="19">
        <div class="app_card  pt-2  pb-5">
          <div class="text-16 my-4">8号教学楼 - 一楼</div>
          <div style="height:calc(100vh - 360px);overflow-y: scroll;">
            <el-row :gutter="15" class="w100 mt-3">
              <el-col class="mb-3" :xs="12" :sm="12" :lg="radioIcon == '1' ? { span: bigCol } : { span: smallCol }" v-for="(item, index) in dataOfTable" :key="index" @click="handelClick(item)">
                <el-card shadow="never" :class="{
                'online':item.online=='1',//在线
                'offline':item.online!='1',//离线
                'fault':item.repairStatus=='1',//故障
                'bigHeight':radioIcon == '1',
                'smallHeight':radioIcon != '1',
                'checkBorder':item.isCheck
                }">
                  <template #header>
                    <div class="card-header" :class="radioIcon == '1' ? 'text-20' : 'text-18'">
                      <div>
                        <span class="tag"></span>
                        <span class="ml-3">{{item.name}}-{{item.online=='1'?'在线':'离线'}}</span>
                      </div>

                      <div class="text-white-50">··· </div>
                    </div>
                  </template>
                  <div style="position-relative">
                    <div class="position-relative float-start w-25 t-c ptb-2" v-for="i in item.equipments" >
                      <span class="typeIcon" :class="`type${i}`" @click.stop="onStop()"></span>
                    </div>
                  </div>

                </el-card>

              </el-col>
            </el-row>
          </div>
          <div class="mt-2">
            <el-pagination background v-model:currentPage="queryParam.page" v-model:page-size="queryParam.pageSize" :page-sizes="paginationOption.pageSizes" :background="false" :layout="paginationOption.layout" :total="paginationOption.total" @size-change="handleChangeSize" @current-change="handleChangeCurrent" />
          </div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="5">
        <div class="app_card  pt-2  pb-5">
          <div class="text-16 my-4">控制面板</div>

          <div style="height:calc(100vh - 330px);overflow-y: scroll;">
            <el-card class="card_bg" shadow="never">
              <template #header>
                <div class="card-header">
                  <span class="text-16 text-white-50">设备名称</span>
                  <el-button type="warning" round size="small">报修</el-button>
                </div>
              </template>
              <el-row v-for="(item,index) in dataOfTable" :key="index" class="plr-2 ptb-2">
                <el-col :span="18" class="text-16">
                  <span class="typeIcon sm" :class="`type${index+1}`"></span> {{item.name}}
                </el-col>
                <el-col :span="6" class="t-r">
                  <el-switch v-model="item.repairStatus" inline-prompt active-value="1" inactive-value="0" active-text="开" inactive-text="关" />
                </el-col>

              </el-row>
              <el-row :gutter="20" class="mt-3">
                <el-col :span="12" class="t-l pl-3">
                  <el-button type="primary" class="w100 rounded-4" plain size="large">上课</el-button>
                </el-col>
                <el-col :span="12" class="t-r pr-3">
                  <el-button type="primary" class="w100 rounded-4" plain size="large">下课</el-button>
                </el-col>
              </el-row>
            </el-card>

          </div>
        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script setup>
/**
 * 面板控制
 */
import { ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import EsAjax from '@/utils/EsAjax';
import ApiUrls from '@/apis/index';
import useAuthStore from '@/stores/useAuthStore';

// ======================================================
//                      变量声明
// ======================================================


const authStore = useAuthStore();
// 表格数据
const dataOfTable = ref([]);
// 表格查询参数
const queryParam = ref({
  q: '',
  search: '',
  orderby: '',
  group_id: 0,
  page: 1,
  pageSize: 10,
})
// 分页栏配置数据
const paginationOption = ref({
  layout: 'total, sizes, prev, pager, next, jumper',
  pageSizes: [10, 20, 50, 100, 500, 1000],
  total: 0,
})
//1大图 2小图
const radioIcon = ref('1');
const bigCol = ref(8);
const smallCol = ref(6);
// 表格多选数据
const multipleSelection = ref([]);









// 点击行内编辑按钮
const onEditRow = (row) => {
  editDialogRef.value.show(row.id, '编辑 ' + row.title);
}

// 点击行内删除按钮
const onDeleteRow = (row) => {
  ElMessageBox.confirm("确定要删除该记录吗？", '警告').then(() => {
    EsAjax.delete(ApiUrls.systemConfigDelete, { data: { id: row.id } })
      .then(res => {
        if (res.data.code !== 200) {
          ElMessage.warning(res.data.msg);
          return;
        }
        loadData();
      })
      .catch(err => { ElMessage.error('网络错误：', err.message) });
  }).catch(() => { });
  console.log(row)
}

// ======================================================
//                      处理事件
// ======================================================

// 处理分页尺寸
const handelClick = (item) => {
  item.isCheck = !item.isCheck
}

// 处理分页尺寸
const handleChangeSize = (val) => {
  console.log(`${val} items per page`);
  queryParam.value.page = 1;
  queryParam.value.pageSize = val;
  loadData();
}

// 处理页码
const handleChangeCurrent = (val) => {
  console.log(`current page: ${val}`)
  queryParam.value.page = val;
  loadData();
}
// 阻止冒泡
const onStop = () => {

}

// ======================================================
//                      处理事件
// ======================================================

const loadData = (query) => {
  console.log('query===', query)

  radioIcon.value = query?.radio_icon


  // roomFault
  EsAjax.post(ApiUrls.roomBusy, queryParam.value).then(res => {
    console.error(res)
    if (res.data.code !== 200) {
      ElMessage.warning(res.data.msg);
      return;
    }
    let { data = [] } = res?.data?.data || []
    if (data && data.length) {
      data.forEach(element => {
        element.isCheck = false
      });
    }
    dataOfTable.value = data;
    paginationOption.value.total = res.data.data.total;
  }).catch(err => {
    ElMessage.error(err.message);
  })
}


defineExpose({
  loadData
})

// loadData();
</script>
<style lang="less" scoped>
:deep(.el-button--primary.is-plain) {
  border: none;
  color: #00A2CC;
  background: rgba(13, 184, 149, 0.1);
}
.tag {
  width: 40px;
  height: 40px;
  display: inline-block;
  position: absolute;
  left: 0px;
  top: 5px;
}
.typeIcon {
  width: 33px;
  height: 33px;
  display: inline-block;
  &.sm {
    width: 15px !important;
    height: 15px !important;
  }
}
:deep(.el-card__header) {
  padding-left: 20px;
  position: relative;
}
.smallHeight {
  height: 220px;
  box-sizing: border-box;
  border-radius: 5px;
  .typeIcon {
    width: 22px;
    height: 22px;
  }
}
.bigHeight {
  height: 250px;
  box-sizing: border-box;
  border-radius: 5px;
  :deep(.el-card__header) {
    padding: 20px;
  }
  .tag {
    top: 13px;
  }
}
.checkBorder {
  border: 2px solid #00A2CC !important;
}
.online {
  .tag {
    background: url("@/assets/img/room/online-tag.png") no-repeat;
    background-size: 100%;
  }
  :deep(.el-card__header) {
    background: linear-gradient(
      90deg,
      rgba(15, 209, 169, 6) 0%,
      rgba(15, 209, 169, 0) 100%
    );
    border-bottom: 4px solid;
    border-image-source: linear-gradient(
      90deg,
      #0fd1a9 0%,
      rgba(15, 209, 169, 0) 100%
    );
    border-image-slice: 1;
  }
}

.fault {
  .tag {
    background: url("@/assets/img/room/fault-tag.png") no-repeat;
    background-size: 100%;
  }
  :deep(.el-card__header) {
    background: linear-gradient(
      90deg,
      rgba(255, 187, 0, 0.6) 0%,
      rgba(255, 187, 0, 0) 100%
    );
    border-bottom: 4px solid;
    border-image-source: linear-gradient(
      90deg,
      #ffbb00 0%,
      rgba(255, 187, 0, 0) 100%
    );
    border-image-slice: 1;
  }
}
.offline {
  .tag {
    background: url("@/assets/img/room/offline-tag.png") no-repeat;
    background-size: 100%;
  }
  :deep(.el-card__header) {
    background: linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.2) 0%,
      rgba(255, 255, 255, 0) 100%
    ) !important;
    border-bottom: 4px solid;
    border-image-source: linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.2) 0%,
      rgba(255, 255, 255, 0) 100%
    ) !important;
    border-image-slice: 1;
  }
}

.type1 {
  background: url("@/assets/img/room/type1.png") no-repeat;
  background-size: 100%;
}
.type2 {
  background: url("@/assets/img/room/type2.png") no-repeat;
  background-size: 100%;
}
.type3 {
  background: url("@/assets/img/room/type3.png") no-repeat;
  background-size: 100%;
}
.type4 {
  background: url("@/assets/img/room/type4.png") no-repeat;
  background-size: 100%;
}
.type5 {
  background: url("@/assets/img/room/type5.png") no-repeat;
  background-size: 100%;
}
.type6 {
  background: url("@/assets/img/room/type6.png") no-repeat;
  background-size: 100%;
}
.type6 {
  background: url("@/assets/img/room/type6.png") no-repeat;
  background-size: 100%;
}
.type7 {
  background: url("@/assets/img/room/type7.png") no-repeat;
  background-size: 100%;
}
.type8 {
  background: url("@/assets/img/room/type8.png") no-repeat;
  background-size: 100%;
}
.type9 {
  background: url("@/assets/img/room/type9.png") no-repeat;
  background-size: 100%;
}
.type10 {
  background: url("@/assets/img/room/type10.png") no-repeat;
  background-size: 100%;
}
.type11 {
  background: url("@/assets/img/room/type11.png") no-repeat;
  background-size: 100%;
}
.type12 {
  background: url("@/assets/img/room/type12.png") no-repeat;
  background-size: 100%;
}
.type13 {
  background: url("@/assets/img/room/type13.png") no-repeat;
  background-size: 100%;
}
.type14 {
  background: url("@/assets/img/room/type14.png") no-repeat;
  background-size: 100%;
}
.type15 {
  background: url("@/assets/img/room/type15.png") no-repeat;
  background-size: 100%;
}
.type16 {
  background: url("@/assets/img/room/type16.png") no-repeat;
  background-size: 100%;
}
.type17 {
  background: url("@/assets/img/room/type17.png") no-repeat;
  background-size: 100%;
}
</style>

